package com.neudu.glsb.controller;

import com.neudu.glsb.commons.JSONReturn;
import com.neudu.glsb.pojo.UserOperationLogs;
import com.neudu.glsb.service.UserOperationLogsService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
import java.util.List;

@RestController
public class UserOperationLogController {
    private static final Logger logger = LoggerFactory.getLogger(UserOperationLogController.class);

    @Autowired
    private UserOperationLogsService userOperationLogsService;

    @Autowired
    private JSONReturn jsonReturn;

    @GetMapping("/logsWithEmployeeName")
    public String getLogsByDate(
            @RequestParam(required = false) @DateTimeFormat(pattern = "yyyy-MM-dd") Date startDate,
            @RequestParam(required = false) @DateTimeFormat(pattern = "yyyy-MM-dd") Date endDate) {
        try {
            logger.info("开始查询操作记录，开始日期: {}, 结束日期: {}", startDate, endDate);
            List<UserOperationLogs> logs = userOperationLogsService.getLogsByDate(startDate, endDate);
            logger.info("查询操作记录成功，共查询到 {} 条记录", logs.size());
            return jsonReturn.returnSuccess(logs);
        } catch (Exception e) {
            logger.error("查询操作记录失败", e);
            return jsonReturn.returnError("查询操作记录失败：" + e.getMessage());
        }
    }
}